package com.hesicare.cgm.entity;

/**
 * @Author 55097
 * @create 2021/12/5 14:48
 */
public class CgmResult<T> {

    private int code;
    private String msg;
    private Boolean success;
    private String timestamp;
    private String data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public CgmResult() {
    }

    /**
     * @Description 接口调用成功返回，适用于不需要返回数据的情况
     * @Author zhaoyu
     * @Date 2019/9/29
     * @Return com.hesicare.business.common.util.BaseResVo
     */
    public static <E> CgmResult<E> success(E data) {
        CgmResult<E> base = new CgmResult<>();
        base.setCode(0);
        base.setData(data.toString());
        base.setMsg(data.toString());
        base.setSuccess(true);
        base.setTimestamp(String.valueOf(System.currentTimeMillis()));
        return base;
    }

    /**
     * @Description 接口调用成功返回，适用于不需要返回数据的情况
     * @Author zhaoyu
     * @Date 2019/9/29
     * @Return com.hesicare.business.common.util.BaseResVo
     */
    public static <E> CgmResult<E> fail(E data) {
        CgmResult<E> base = new CgmResult<>();
        base.setCode(1);
        base.setData(data.toString());
        base.setMsg(data.toString());
        base.setSuccess(false);
        base.setTimestamp(String.valueOf(System.currentTimeMillis()));
        return base;
    }

    @Override
    public String toString() {
        return "CGMresult{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", success=" + success +
                ", timestamp='" + timestamp + '\'' +
                ", data='" + data + '\'' +
                '}';
    }

}
